package org.example.validation.handlers;


import org.example.validation.ValidatorContext;
import org.example.validation.ValidatorHandler;

public class LengthValidatorHandler implements ValidatorHandler {

    private int length;

    public LengthValidatorHandler(int length) {
        this.length = length;
    }


    @Override
    public void validate(Object obj, ValidatorContext context) {
        //所校验字段必须是String 类型
        if(obj instanceof String ){
            if(((String) obj).length() > length){
                context.addErrorMessage("字段长度不能大于"+length);
            }
        }
    }
}
